package com.hjj.homieMatching.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hjj.homieMatching.service.ws.WebSocket;
import lombok.extern.slf4j.Slf4j;

/**
 * WebSocket状态控制器
 * 提供一个HTTP端点来检查WebSocket服务状态
 */
@RestController
@RequestMapping("/websocket")
@Slf4j
public class WebSocketController {
    
    /**
     * 获取WebSocket服务状态
     * @return WebSocket服务状态信息
     */
    @GetMapping("/status")
    public String getStatus() {
        try {
            int onlineCount = WebSocket.getOnlineCount();
            log.info("当前WebSocket在线用户数: {}", onlineCount);
            return "WebSocket服务运行正常，当前在线用户数: " + onlineCount;
        } catch (Exception e) {
            log.error("获取WebSocket状态时出错", e);
            return "WebSocket服务异常: " + e.getMessage();
        }
    }
    
    /**
     * WebSocket健康检查
     * @return 健康状态
     */
    @GetMapping("/health")
    public String health() {
        return "WebSocket服务运行正常";
    }
    
    /**
     * WebSocket配置信息
     * @return 配置信息
     */
    @GetMapping("/config")
    public String config() {
        return "WebSocket端点: /websocket/{userId}/{teamId}";
    }
} 